package com.cskaoyan.controller.vx.search;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.vxBo.search.SearchClearBO;
import com.cskaoyan.bean.vo.vxVo.search.SearchIndexVo;
import com.cskaoyan.service.vx.search.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 搜索模块
 * /wx/search/
 *
 * @author: 陈慧颖
 * @time: Created by chy on 2022/6/7 11:47
 */
@RestController
@RequestMapping("wx/search")
public class SearchController {

    @Autowired
    SearchService searchService;

    /**
     * GET  /wx/search/index接口; 客户端未传递参数;
     *
     * @return
     */
    @RequestMapping("index")
    public BaseRespVo index() {
        SearchIndexVo searchIndexVo = searchService.index();
        return BaseRespVo.ok(searchIndexVo);
    }

    /**
     * /wx/search/helper?keyword=%E6%97%A5%E5%BC%8F
     * 输入`XXXX`,响应 helper;
     * @param keyword
     * @return
     */
    @RequestMapping("helper")
    public BaseRespVo helper(String keyword){
        List<String> stringList = searchService.helper(keyword);
        return BaseRespVo.ok(stringList);

    }

    /**
     * POST /wx/search/clearhistory; 客户端没有携带参数;
     * 删除历史记录,
     * /wx/search/clearhistory
     * 即便实现,也是假删除;
     *
     * @return
     */
    @RequestMapping("clearhistory")
    public BaseRespVo clearhistory(@RequestBody SearchClearBO searchClearBO){
        searchService.clearhistory(searchClearBO);
        return BaseRespVo.ok(null);
    }

}
